import Vue from "vue";
import VueRouter from "vue-router";
// import Login from "../views/Login/Index.vue";

import Index from "../views/Index/Index.vue";
// import Register from "../views/Register/Index.vue";

// index三件套
// import State from "../views/Index/Components/state.vue";
// import Management from "../views/Index/Components/management.vue";
// import Logger from "../views/Index/Components/logger.vue";
// import Survey from "../views/Index/Components/survey.vue";

// import ERR404 from "../views/400OR500/404.vue";
// import ERR500 from "../views/400OR500/500.vue";

// import Test from "../views/Components/Test.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Index",
    component: Index,
    // 设置默认渲染的路由
    redirect: '/survey',
    children: [{
        path: "/survey",
        name: "survey",
        // component: resolve => require(['../views/Index/Components/survey.vue'], resolve),
        component: () => import("../views/Index/Components/survey.vue")
      },
      {
        path: "/state",
        name: "state",
        component: resolve => require(['../views/Index/Components/state.vue'], resolve)
      },


      {
        path: "/management",
        name: "management",
        component: resolve => require(['../views/Index/Components/management.vue'], resolve)
      },
      {
        path: "/logger",
        name: "logger",
        component: resolve => require(['../views/Index/Components/Logger/index.vue'], resolve),
        children: [
          {
            path: "/logger/lockLogger",
            name: "lockLogger",
            component: resolve => require(['../views/Index/Components/Logger/lockLogger.vue'], resolve)
          },
          {
            path:"/logger/stateLogger",
            name:"stateLogger",
            component: resolve => require(["../views/Index/Components/Logger/stateLogger.vue"], resolve)
          },
          
        ]
      },
      // 超级管理页面
      {
        name:"root",
        path:"/root",
        component: resolve => require(['../views/Index/Components/Root/index.vue'], resolve),
        children: [
          {
            path: "/root/lockManage",
            name: "lockManage",
            component: resolve => require(['../views/Index/Components/Root/lockManage.vue'], resolve)
          },
          {
            path: "/root/tcpLogger",
            name: "tcpLogger",
            component: resolve => require(['../views/Index/Components/Root/TcpLogger.vue'], resolve)
          },
          {
            path:"/root/lockNumber",
            name:"lockNumber",
            component: resolve => require(['../views/Index/Components/Root/lockNumber.vue'], resolve)
          }
        ]
      },
      // 个人信息页
      {
        path: '/userInfo',
        name: 'userInfo',
        component: resolve => require(['../views/UserInfo/Index.vue'], resolve)
      },
      {
        path: '/test',
        name: 'test',
        component: resolve => require(['../views/Index/Components/Test.vue'], resolve)
      }
    ]
  },
  // 登录界面
  {
    path: "/login",
    name: "Login",
    component: resolve => require(['../views/Login/Index.vue'], resolve),
    children:[
      {
        path:"/login",
        name:"Login",
        component: resolve => require(['../views/Login/Login.vue'], resolve)
      },
      {
        path:"/register",
        name:"Register",
        component: resolve => require(['../views/Login/Register.vue'], resolve)
      },
    ]
  },
  
  {
    path: '/ERR404',
    name: 'ERR404',
    component: resolve => require(['../views/400OR500/404.vue'], resolve)
  },
  {
    path: '/ERR500',
    name: 'ERR500',
    component: resolve => require(['../views/400OR500/500.vue'], resolve)
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router;